package com.fingard.dsp.bank.directbank.chinapay05;

import java.io.File;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.SendBankRespose;
import com.fingard.dsp.bank.directbank.bankInterface.IAcceptNotice;
import com.fingard.generalobj.NoticeReq;
import com.fingard.generalobj.NoticeResp;
import com.fingard.net.listener.SocketReceiver;
import com.fingard.text.StringHelper;

public class ChinaPay05AcceptNotice extends ChinaPay05Base implements IAcceptNotice {
	@Override
	public NoticeResp dealNotice(NoticeReq pNtReq) throws Exception {
		
		NoticeResp resp = new NoticeResp();
    	String p_req = pNtReq.getReqString();
    	WriteBankLogLn("接收到请求：" + pNtReq.getFullString());
		
		String downFileURL = p_req.substring(p_req.indexOf("=" + 1));
		String downFileName = downFileURL.substring(downFileURL.lastIndexOf("/")+1);
		String localPath = getBankConfig().getValueAsString("statementFileFath");
		if (StringHelper.isNullOrEmpty(localPath)) {
			throw new Exception("配置文件字段'statementFileFath'缺失,请检查config.xml相关配置");
		}
		localPath = StringHelper.trimEnd(localPath, File.separator) + File.separator;
		String filePath =localPath + Format.Date8Format.format(Format.Date8Format.parse(downFileName.split("_")[1]));
		File dir = new File(filePath);
        if (!dir.exists()) {
            dir.mkdirs();
        }
		filePath = filePath + File.separator + downFileName;
		WriteBankLogLn2("待下载文件保存本机路径:" + filePath);
		
		SendBankRespose retResp = smsGet(downFileURL, filePath);
		WriteBankLogStep3(retResp);
		
		String tmpStrRet = "ChinapayOK";
        WriteBankLogLn("响应："+ tmpStrRet);
        resp.respBytes = tmpStrRet.getBytes(pNtReq.reqCharset);
    	return resp;
	}

	@Override
	public void getContentLength(SocketReceiver p_receiver) throws Exception {
	}
}
